





<!DOCTYPE html>
<html class="writer-html5" lang="zh-CN" >
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>为x86CPU 自动调优一个卷积网络 &mdash; tvm 0.8.dev1982 文档</title>
  

  
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/gallery.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/css/tlcpack_theme.css" type="text/css" />

  
  
    <link rel="shortcut icon" href="../../_static/tvm-logo-square.png"/>
  

  
  
  
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/translations.js"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <script type="text/javascript" src="../../_static/js/tlcpack_theme.js"></script>
    <link rel="index" title="索引" href="../../genindex.html" />
    <link rel="search" title="搜索" href="../../search.html" />
    <link rel="next" title="Auto-tuning a Convolutional Network for ARM CPU" href="tune_relay_arm.html" />
    <link rel="prev" title="Auto-tuning a Convolutional Network for NVIDIA GPU" href="tune_relay_cuda.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    
<header class="header">
    <div class="innercontainer">
      <div class="headerInner d-flex justify-content-between align-items-center">
          <div class="headerLogo">
               <a href="https://tvm.apache.org/"><img src=https://tvm.apache.org/assets/images/logo.svg alt="logo"></a>
          </div>

          <div id="headMenu" class="headerNav">
            <button type="button" id="closeHeadMenu" class="navCloseBtn"><img src="../../_static/img/close-icon.svg" alt="Close"></button>
             <ul class="nav">
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/community>Community</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/download>Download</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/vta>VTA</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/blog>Blog</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/docs>Docs</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvmconf.org>Conference</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://github.com/apache/tvm/>Github</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvmchinese.github.io/declaration_zh_CN.html>About-Translators</a>
                </li>
             </ul>
               <div class="responsivetlcdropdown">
                 <button type="button" class="btn-link">
                   ASF
                 </button>
                 <ul>
                     <li>
                       <a href=https://apache.org/>Apache Homepage</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/licenses/>License</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/sponsorship.html>Sponsorship</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/security/>Security</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/thanks.html>Thanks</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/events/current-event>Events</a>
                     </li>
                     <li>
                       <a href=https://www.zhihu.com/column/c_1429578595417563136>Zhihu</a>
                     </li>
                 </ul>
               </div>
          </div>
            <div class="responsiveMenuIcon">
              <button type="button" id="menuBtn" class="btn-menu"><img src="../../_static/img/menu-icon.svg" alt="Menu Icon"></button>
            </div>

            <div class="tlcDropdown">
              <div class="dropdown">
                <button type="button" class="btn-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  ASF
                </button>
                <div class="dropdown-menu dropdown-menu-right">
                  <ul>
                     <li>
                       <a href=https://apache.org/>Apache Homepage</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/licenses/>License</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/sponsorship.html>Sponsorship</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/security/>Security</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/thanks.html>Thanks</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/events/current-event>Events</a>
                     </li>
                     <li>
                       <a href=https://www.zhihu.com/column/c_1429578595417563136>Zhihu</a>
                     </li>
                  </ul>
                </div>
              </div>
          </div>
       </div>
    </div>
 </header>
 
    <nav data-toggle="wy-nav-shift" class="wy-nav-side fixed">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../index.html">
          

          
            
            <img src="../../_static/tvm-logo-small.png" class="logo" alt="Logo"/>
          
          </a>

          
            
            
                <div class="version">
                  0.8.dev1982
                </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption" role="heading"><span class="caption-text">如何开始</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../install/index.html">安装 TVM</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../contribute/index.html">贡献者指南</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">用户引导</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../tutorial/index.html">User Tutorial</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../index.html">How To Guides</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../compile_models/index.html">编译深度学习模型</a></li>
<li class="toctree-l2"><a class="reference internal" href="../deploy/index.html">TVM 部署模型和集成</a></li>
<li class="toctree-l2"><a class="reference internal" href="../work_with_relay/index.html">Work With Relay</a></li>
<li class="toctree-l2"><a class="reference internal" href="../work_with_schedules/index.html">Work With Tensor Expression and Schedules</a></li>
<li class="toctree-l2"><a class="reference internal" href="../optimize_operators/index.html">优化张量算子</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="index.html">Auto-Tune with Templates and AutoTVM</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="tune_conv2d_cuda.html">Tuning High Performance Convolution on NVIDIA GPUs</a></li>
<li class="toctree-l3"><a class="reference internal" href="tune_relay_cuda.html">Auto-tuning a Convolutional Network for NVIDIA GPU</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">为x86CPU 自动调优一个卷积网络</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#define-network">Define network</a></li>
<li class="toctree-l4"><a class="reference internal" href="#configure-tensor-tuning-settings-and-create-tasks">Configure tensor tuning settings and create tasks</a></li>
<li class="toctree-l4"><a class="reference internal" href="#sample-output">样本输出</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="tune_relay_arm.html">Auto-tuning a Convolutional Network for ARM CPU</a></li>
<li class="toctree-l3"><a class="reference internal" href="tune_relay_mobile_gpu.html">Auto-tuning a Convolutional Network for Mobile GPU</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../tune_with_autoscheduler/index.html">Use AutoScheduler for Template-Free Scheduling</a></li>
<li class="toctree-l2"><a class="reference internal" href="../work_with_microtvm/index.html">Work With microTVM</a></li>
<li class="toctree-l2"><a class="reference internal" href="../extend_tvm/index.html">Extend TVM</a></li>
<li class="toctree-l2"><a class="reference internal" href="../profile/index.html">Profile Models</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../errors.html">Handle TVM Errors</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../faq.html">常见提问</a></li>
</ul>
</li>
</ul>
<p class="caption" role="heading"><span class="caption-text">开发者引导</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../dev/tutorial/index.html">Developer Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/how_to/how_to.html">开发者指南</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">架构指南</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../arch/index.html">Design and Architecture</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">主题引导</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../topic/microtvm/index.html">microTVM：裸机使用TVM</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../topic/vta/index.html">VTA: Versatile Tensor Accelerator</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">参考指南</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../reference/langref/index.html">语言参考</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../reference/api/python/index.html">Python API</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../reference/api/links.html">Other APIs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../reference/publications.html">Publications</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../genindex.html">索引</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
      
      <nav class="wy-nav-top" aria-label="top navigation" data-toggle="wy-nav-top">
        
            <div class="togglemenu">

            </div>
            <div class="nav-content">
              <!-- tvm -->
              Table of content
            </div>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        

          




















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html">Docs</a> <span class="br-arrow">></span></li>
        
          <li><a href="../index.html">How To Guides</a> <span class="br-arrow">></span></li>
        
          <li><a href="index.html">Auto-Tune with Templates and AutoTVM</a> <span class="br-arrow">></span></li>
        
      <li>为x86CPU 自动调优一个卷积网络</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="../../_sources/how_to/tune_with_autotvm/tune_relay_x86.rst.txt" rel="nofollow"> <img src="../../_static//img/source.svg" alt="viewsource"/></a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="sphx-glr-download-link-note admonition note">
<p class="admonition-title">注解</p>
<p>点击 <a class="reference internal" href="#sphx-glr-download-how-to-tune-with-autotvm-tune-relay-x86-py"><span class="std std-ref">此处</span></a> 获取完整示例代码</p>
</div>
<div class="sphx-glr-example-title section" id="auto-tuning-a-convolutional-network-for-x86-cpu">
<span id="tune-relay-x86"></span><span id="sphx-glr-how-to-tune-with-autotvm-tune-relay-x86-py"></span><h1>为x86CPU 自动调优一个卷积网络<a class="headerlink" href="#auto-tuning-a-convolutional-network-for-x86-cpu" title="永久链接至标题">¶</a></h1>
<p><strong>作者</strong>: <a class="reference external" href="https://github.com/kevinthesun">Yao Wang</a>, <a class="reference external" href="https://github.com/eqy">Eddie Yan</a></p>
<p>This is a tutorial about how to tune convolution neural network
for x86 CPU.</p>
<p>Note that this tutorial will not run on Windows or recent versions of macOS. To
get it to run, you will need to wrap the body of this tutorial in a <code class="code docutils literal notranslate"><span class="pre">if</span>
<span class="pre">__name__</span> <span class="pre">==</span> <span class="pre">&quot;__main__&quot;:</span></code> block.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>

<span class="kn">import</span> <span class="nn">tvm</span>
<span class="kn">from</span> <span class="nn">tvm</span> <span class="k">import</span> <span class="n">relay</span><span class="p">,</span> <span class="n">autotvm</span>
<span class="kn">from</span> <span class="nn">tvm.relay</span> <span class="k">import</span> <span class="n">testing</span>
<span class="kn">from</span> <span class="nn">tvm.autotvm.tuner</span> <span class="k">import</span> <span class="n">XGBTuner</span><span class="p">,</span> <span class="n">GATuner</span><span class="p">,</span> <span class="n">RandomTuner</span><span class="p">,</span> <span class="n">GridSearchTuner</span>
<span class="kn">from</span> <span class="nn">tvm.autotvm.graph_tuner</span> <span class="k">import</span> <span class="n">DPTuner</span><span class="p">,</span> <span class="n">PBQPTuner</span>
<span class="kn">import</span> <span class="nn">tvm.contrib.graph_executor</span> <span class="k">as</span> <span class="nn">runtime</span>
</pre></div>
</div>
<div class="section" id="define-network">
<h2>Define network<a class="headerlink" href="#define-network" title="永久链接至标题">¶</a></h2>
<p>First we need to define the network in relay frontend API.
We can either load some pre-defined network from <code class="code docutils literal notranslate"><span class="pre">relay.testing</span></code>
or building <a class="reference internal" href="../../reference/api/python/relay/testing.html#module-tvm.relay.testing.resnet" title="tvm.relay.testing.resnet"><code class="xref any py py-mod docutils literal notranslate"><span class="pre">relay.testing.resnet</span></code></a> with relay.
We can also load models from MXNet, ONNX and TensorFlow.</p>
<p>In this tutorial, we choose resnet-18 as tuning example.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">get_network</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">batch_size</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Get the symbol definition and random weight of a network&quot;&quot;&quot;</span>
    <span class="n">input_shape</span> <span class="o">=</span> <span class="p">(</span><span class="n">batch_size</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">224</span><span class="p">,</span> <span class="mi">224</span><span class="p">)</span>
    <span class="n">output_shape</span> <span class="o">=</span> <span class="p">(</span><span class="n">batch_size</span><span class="p">,</span> <span class="mi">1000</span><span class="p">)</span>

    <span class="k">if</span> <span class="s2">&quot;resnet&quot;</span> <span class="ow">in</span> <span class="n">name</span><span class="p">:</span>
        <span class="n">n_layer</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;-&quot;</span><span class="p">)[</span><span class="mi">1</span><span class="p">])</span>
        <span class="n">mod</span><span class="p">,</span> <span class="n">params</span> <span class="o">=</span> <span class="n">relay</span><span class="o">.</span><span class="n">testing</span><span class="o">.</span><span class="n">resnet</span><span class="o">.</span><span class="n">get_workload</span><span class="p">(</span>
            <span class="n">num_layers</span><span class="o">=</span><span class="n">n_layer</span><span class="p">,</span> <span class="n">batch_size</span><span class="o">=</span><span class="n">batch_size</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span>
        <span class="p">)</span>
    <span class="k">elif</span> <span class="s2">&quot;vgg&quot;</span> <span class="ow">in</span> <span class="n">name</span><span class="p">:</span>
        <span class="n">n_layer</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;-&quot;</span><span class="p">)[</span><span class="mi">1</span><span class="p">])</span>
        <span class="n">mod</span><span class="p">,</span> <span class="n">params</span> <span class="o">=</span> <span class="n">relay</span><span class="o">.</span><span class="n">testing</span><span class="o">.</span><span class="n">vgg</span><span class="o">.</span><span class="n">get_workload</span><span class="p">(</span>
            <span class="n">num_layers</span><span class="o">=</span><span class="n">n_layer</span><span class="p">,</span> <span class="n">batch_size</span><span class="o">=</span><span class="n">batch_size</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span>
        <span class="p">)</span>
    <span class="k">elif</span> <span class="n">name</span> <span class="o">==</span> <span class="s2">&quot;mobilenet&quot;</span><span class="p">:</span>
        <span class="n">mod</span><span class="p">,</span> <span class="n">params</span> <span class="o">=</span> <span class="n">relay</span><span class="o">.</span><span class="n">testing</span><span class="o">.</span><span class="n">mobilenet</span><span class="o">.</span><span class="n">get_workload</span><span class="p">(</span><span class="n">batch_size</span><span class="o">=</span><span class="n">batch_size</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span><span class="p">)</span>
    <span class="k">elif</span> <span class="n">name</span> <span class="o">==</span> <span class="s2">&quot;squeezenet_v1.1&quot;</span><span class="p">:</span>
        <span class="n">mod</span><span class="p">,</span> <span class="n">params</span> <span class="o">=</span> <span class="n">relay</span><span class="o">.</span><span class="n">testing</span><span class="o">.</span><span class="n">squeezenet</span><span class="o">.</span><span class="n">get_workload</span><span class="p">(</span>
            <span class="n">batch_size</span><span class="o">=</span><span class="n">batch_size</span><span class="p">,</span> <span class="n">version</span><span class="o">=</span><span class="s2">&quot;1.1&quot;</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span>
        <span class="p">)</span>
    <span class="k">elif</span> <span class="n">name</span> <span class="o">==</span> <span class="s2">&quot;inception_v3&quot;</span><span class="p">:</span>
        <span class="n">input_shape</span> <span class="o">=</span> <span class="p">(</span><span class="n">batch_size</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">299</span><span class="p">,</span> <span class="mi">299</span><span class="p">)</span>
        <span class="n">mod</span><span class="p">,</span> <span class="n">params</span> <span class="o">=</span> <span class="n">relay</span><span class="o">.</span><span class="n">testing</span><span class="o">.</span><span class="n">inception_v3</span><span class="o">.</span><span class="n">get_workload</span><span class="p">(</span><span class="n">batch_size</span><span class="o">=</span><span class="n">batch_size</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span><span class="p">)</span>
    <span class="k">elif</span> <span class="n">name</span> <span class="o">==</span> <span class="s2">&quot;mxnet&quot;</span><span class="p">:</span>
        <span class="c1"># an example for mxnet model</span>
        <span class="kn">from</span> <span class="nn">mxnet.gluon.model_zoo.vision</span> <span class="k">import</span> <span class="n">get_model</span>

        <span class="n">block</span> <span class="o">=</span> <span class="n">get_model</span><span class="p">(</span><span class="s2">&quot;resnet18_v1&quot;</span><span class="p">,</span> <span class="n">pretrained</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="n">mod</span><span class="p">,</span> <span class="n">params</span> <span class="o">=</span> <span class="n">relay</span><span class="o">.</span><span class="n">frontend</span><span class="o">.</span><span class="n">from_mxnet</span><span class="p">(</span><span class="n">block</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">{</span><span class="n">input_name</span><span class="p">:</span> <span class="n">input_shape</span><span class="p">},</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span><span class="p">)</span>
        <span class="n">net</span> <span class="o">=</span> <span class="n">mod</span><span class="p">[</span><span class="s2">&quot;main&quot;</span><span class="p">]</span>
        <span class="n">net</span> <span class="o">=</span> <span class="n">relay</span><span class="o">.</span><span class="n">Function</span><span class="p">(</span>
            <span class="n">net</span><span class="o">.</span><span class="n">params</span><span class="p">,</span> <span class="n">relay</span><span class="o">.</span><span class="n">nn</span><span class="o">.</span><span class="n">softmax</span><span class="p">(</span><span class="n">net</span><span class="o">.</span><span class="n">body</span><span class="p">),</span> <span class="kc">None</span><span class="p">,</span> <span class="n">net</span><span class="o">.</span><span class="n">type_params</span><span class="p">,</span> <span class="n">net</span><span class="o">.</span><span class="n">attrs</span>
        <span class="p">)</span>
        <span class="n">mod</span> <span class="o">=</span> <span class="n">tvm</span><span class="o">.</span><span class="n">IRModule</span><span class="o">.</span><span class="n">from_expr</span><span class="p">(</span><span class="n">net</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Unsupported network: &quot;</span> <span class="o">+</span> <span class="n">name</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">mod</span><span class="p">,</span> <span class="n">params</span><span class="p">,</span> <span class="n">input_shape</span><span class="p">,</span> <span class="n">output_shape</span>


<span class="c1"># Replace &quot;llvm&quot; with the correct target of your CPU.</span>
<span class="c1"># For example, for AWS EC2 c5 instance with Intel Xeon</span>
<span class="c1"># Platinum 8000 series, the target should be &quot;llvm -mcpu=skylake-avx512&quot;.</span>
<span class="c1"># For AWS EC2 c4 instance with Intel Xeon E5-2666 v3, it should be</span>
<span class="c1"># &quot;llvm -mcpu=core-avx2&quot;.</span>
<span class="n">target</span> <span class="o">=</span> <span class="s2">&quot;llvm&quot;</span>

<span class="n">batch_size</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">dtype</span> <span class="o">=</span> <span class="s2">&quot;float32&quot;</span>
<span class="n">model_name</span> <span class="o">=</span> <span class="s2">&quot;resnet-18&quot;</span>
<span class="n">log_file</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">.log&quot;</span> <span class="o">%</span> <span class="n">model_name</span>
<span class="n">graph_opt_sch_file</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">_graph_opt.log&quot;</span> <span class="o">%</span> <span class="n">model_name</span>

<span class="c1"># Set the input name of the graph</span>
<span class="c1"># For ONNX models, it is typically &quot;0&quot;.</span>
<span class="n">input_name</span> <span class="o">=</span> <span class="s2">&quot;data&quot;</span>

<span class="c1"># Set number of threads used for tuning based on the number of</span>
<span class="c1"># physical CPU cores on your machine.</span>
<span class="n">num_threads</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">&quot;TVM_NUM_THREADS&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">num_threads</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="configure-tensor-tuning-settings-and-create-tasks">
<h2>Configure tensor tuning settings and create tasks<a class="headerlink" href="#configure-tensor-tuning-settings-and-create-tasks" title="永久链接至标题">¶</a></h2>
<p>To get better kernel execution performance on x86 CPU,
we need to change data layout of convolution kernel from
“NCHW” to “NCHWc”. To deal with this situation, we define
conv2d_NCHWc operator in topi. We will tune this operator
instead of plain conv2d.</p>
<p>We will use local mode for tuning configuration. RPC tracker
mode can be setup similarly to the approach in
<a class="reference internal" href="tune_relay_arm.html#tune-relay-arm"><span class="std std-ref">Auto-tuning a Convolutional Network for ARM CPU</span></a> tutorial.</p>
<p>To perform a precise measurement, we should repeat the measurement several
times and use the average of results. In addition, we need to flush the cache
for the weight tensors between repeated measurements. This can make the measured
latency of one operator closer to its actual latency during end-to-end inference.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">tuning_option</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s2">&quot;log_filename&quot;</span><span class="p">:</span> <span class="n">log_file</span><span class="p">,</span>
    <span class="s2">&quot;tuner&quot;</span><span class="p">:</span> <span class="s2">&quot;random&quot;</span><span class="p">,</span>
    <span class="s2">&quot;early_stopping&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
    <span class="s2">&quot;measure_option&quot;</span><span class="p">:</span> <span class="n">autotvm</span><span class="o">.</span><span class="n">measure_option</span><span class="p">(</span>
        <span class="n">builder</span><span class="o">=</span><span class="n">autotvm</span><span class="o">.</span><span class="n">LocalBuilder</span><span class="p">(),</span>
        <span class="n">runner</span><span class="o">=</span><span class="n">autotvm</span><span class="o">.</span><span class="n">LocalRunner</span><span class="p">(</span>
            <span class="n">number</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">repeat</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">min_repeat_ms</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">enable_cpu_cache_flush</span><span class="o">=</span><span class="kc">True</span>
        <span class="p">),</span>
    <span class="p">),</span>
<span class="p">}</span>


<span class="c1"># You can skip the implementation of this function for this tutorial.</span>
<span class="k">def</span> <span class="nf">tune_kernels</span><span class="p">(</span>
    <span class="n">tasks</span><span class="p">,</span> <span class="n">measure_option</span><span class="p">,</span> <span class="n">tuner</span><span class="o">=</span><span class="s2">&quot;gridsearch&quot;</span><span class="p">,</span> <span class="n">early_stopping</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">log_filename</span><span class="o">=</span><span class="s2">&quot;tuning.log&quot;</span>
<span class="p">):</span>

    <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">task</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">tasks</span><span class="p">):</span>
        <span class="n">prefix</span> <span class="o">=</span> <span class="s2">&quot;[Task </span><span class="si">%2d</span><span class="s2">/</span><span class="si">%2d</span><span class="s2">] &quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">tasks</span><span class="p">))</span>

        <span class="c1"># create tuner</span>
        <span class="k">if</span> <span class="n">tuner</span> <span class="o">==</span> <span class="s2">&quot;xgb&quot;</span> <span class="ow">or</span> <span class="n">tuner</span> <span class="o">==</span> <span class="s2">&quot;xgb-rank&quot;</span><span class="p">:</span>
            <span class="n">tuner_obj</span> <span class="o">=</span> <span class="n">XGBTuner</span><span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">loss_type</span><span class="o">=</span><span class="s2">&quot;rank&quot;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">tuner</span> <span class="o">==</span> <span class="s2">&quot;ga&quot;</span><span class="p">:</span>
            <span class="n">tuner_obj</span> <span class="o">=</span> <span class="n">GATuner</span><span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">pop_size</span><span class="o">=</span><span class="mi">50</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">tuner</span> <span class="o">==</span> <span class="s2">&quot;random&quot;</span><span class="p">:</span>
            <span class="n">tuner_obj</span> <span class="o">=</span> <span class="n">RandomTuner</span><span class="p">(</span><span class="n">task</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">tuner</span> <span class="o">==</span> <span class="s2">&quot;gridsearch&quot;</span><span class="p">:</span>
            <span class="n">tuner_obj</span> <span class="o">=</span> <span class="n">GridSearchTuner</span><span class="p">(</span><span class="n">task</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid tuner: &quot;</span> <span class="o">+</span> <span class="n">tuner</span><span class="p">)</span>

        <span class="c1"># do tuning</span>
        <span class="n">n_trial</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">task</span><span class="o">.</span><span class="n">config_space</span><span class="p">)</span>
        <span class="n">tuner_obj</span><span class="o">.</span><span class="n">tune</span><span class="p">(</span>
            <span class="n">n_trial</span><span class="o">=</span><span class="n">n_trial</span><span class="p">,</span>
            <span class="n">early_stopping</span><span class="o">=</span><span class="n">early_stopping</span><span class="p">,</span>
            <span class="n">measure_option</span><span class="o">=</span><span class="n">measure_option</span><span class="p">,</span>
            <span class="n">callbacks</span><span class="o">=</span><span class="p">[</span>
                <span class="n">autotvm</span><span class="o">.</span><span class="n">callback</span><span class="o">.</span><span class="n">progress_bar</span><span class="p">(</span><span class="n">n_trial</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="n">prefix</span><span class="p">),</span>
                <span class="n">autotvm</span><span class="o">.</span><span class="n">callback</span><span class="o">.</span><span class="n">log_to_file</span><span class="p">(</span><span class="n">log_filename</span><span class="p">),</span>
            <span class="p">],</span>
        <span class="p">)</span>


<span class="c1"># Use graph tuner to achieve graph level optimal schedules</span>
<span class="c1"># Set use_DP=False if it takes too long to finish.</span>
<span class="k">def</span> <span class="nf">tune_graph</span><span class="p">(</span><span class="n">graph</span><span class="p">,</span> <span class="n">dshape</span><span class="p">,</span> <span class="n">records</span><span class="p">,</span> <span class="n">opt_sch_file</span><span class="p">,</span> <span class="n">use_DP</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
    <span class="n">target_op</span> <span class="o">=</span> <span class="p">[</span>
        <span class="n">relay</span><span class="o">.</span><span class="n">op</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;nn.conv2d&quot;</span><span class="p">),</span>
    <span class="p">]</span>
    <span class="n">Tuner</span> <span class="o">=</span> <span class="n">DPTuner</span> <span class="k">if</span> <span class="n">use_DP</span> <span class="k">else</span> <span class="n">PBQPTuner</span>
    <span class="n">executor</span> <span class="o">=</span> <span class="n">Tuner</span><span class="p">(</span><span class="n">graph</span><span class="p">,</span> <span class="p">{</span><span class="n">input_name</span><span class="p">:</span> <span class="n">dshape</span><span class="p">},</span> <span class="n">records</span><span class="p">,</span> <span class="n">target_op</span><span class="p">,</span> <span class="n">target</span><span class="p">)</span>
    <span class="n">executor</span><span class="o">.</span><span class="n">benchmark_layout_transform</span><span class="p">(</span><span class="n">min_exec_num</span><span class="o">=</span><span class="mi">2000</span><span class="p">)</span>
    <span class="n">executor</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
    <span class="n">executor</span><span class="o">.</span><span class="n">write_opt_sch2record_file</span><span class="p">(</span><span class="n">opt_sch_file</span><span class="p">)</span>
</pre></div>
</div>
<p>Finally, we launch tuning jobs and evaluate the end-to-end performance.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">evaluate_performance</span><span class="p">(</span><span class="n">lib</span><span class="p">,</span> <span class="n">data_shape</span><span class="p">):</span>
    <span class="c1"># upload parameters to device</span>
    <span class="n">dev</span> <span class="o">=</span> <span class="n">tvm</span><span class="o">.</span><span class="n">cpu</span><span class="p">()</span>
    <span class="n">data_tvm</span> <span class="o">=</span> <span class="n">tvm</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">((</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">uniform</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="n">data_shape</span><span class="p">))</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">dtype</span><span class="p">))</span>
    <span class="n">module</span> <span class="o">=</span> <span class="n">runtime</span><span class="o">.</span><span class="n">GraphModule</span><span class="p">(</span><span class="n">lib</span><span class="p">[</span><span class="s2">&quot;default&quot;</span><span class="p">](</span><span class="n">dev</span><span class="p">))</span>
    <span class="n">module</span><span class="o">.</span><span class="n">set_input</span><span class="p">(</span><span class="n">input_name</span><span class="p">,</span> <span class="n">data_tvm</span><span class="p">)</span>

    <span class="c1"># evaluate</span>
    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Evaluate inference time cost...&quot;</span><span class="p">)</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">module</span><span class="o">.</span><span class="n">benchmark</span><span class="p">(</span><span class="n">dev</span><span class="p">,</span> <span class="n">number</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">repeat</span><span class="o">=</span><span class="mi">3</span><span class="p">))</span>


<span class="k">def</span> <span class="nf">tune_and_evaluate</span><span class="p">(</span><span class="n">tuning_opt</span><span class="p">):</span>
    <span class="c1"># extract workloads from relay program</span>
    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Extract tasks...&quot;</span><span class="p">)</span>
    <span class="n">mod</span><span class="p">,</span> <span class="n">params</span><span class="p">,</span> <span class="n">data_shape</span><span class="p">,</span> <span class="n">out_shape</span> <span class="o">=</span> <span class="n">get_network</span><span class="p">(</span><span class="n">model_name</span><span class="p">,</span> <span class="n">batch_size</span><span class="p">)</span>
    <span class="n">tasks</span> <span class="o">=</span> <span class="n">autotvm</span><span class="o">.</span><span class="n">task</span><span class="o">.</span><span class="n">extract_from_program</span><span class="p">(</span>
        <span class="n">mod</span><span class="p">[</span><span class="s2">&quot;main&quot;</span><span class="p">],</span> <span class="n">target</span><span class="o">=</span><span class="n">target</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">params</span><span class="p">,</span> <span class="n">ops</span><span class="o">=</span><span class="p">(</span><span class="n">relay</span><span class="o">.</span><span class="n">op</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;nn.conv2d&quot;</span><span class="p">),)</span>
    <span class="p">)</span>

    <span class="c1"># run tuning tasks</span>
    <span class="n">tune_kernels</span><span class="p">(</span><span class="n">tasks</span><span class="p">,</span> <span class="o">**</span><span class="n">tuning_opt</span><span class="p">)</span>
    <span class="n">tune_graph</span><span class="p">(</span><span class="n">mod</span><span class="p">[</span><span class="s2">&quot;main&quot;</span><span class="p">],</span> <span class="n">data_shape</span><span class="p">,</span> <span class="n">log_file</span><span class="p">,</span> <span class="n">graph_opt_sch_file</span><span class="p">)</span>

    <span class="c1"># compile kernels in default mode</span>
    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Evaluation of the network compiled in &#39;default&#39; mode without auto tune:&quot;</span><span class="p">)</span>
    <span class="k">with</span> <span class="n">tvm</span><span class="o">.</span><span class="n">transform</span><span class="o">.</span><span class="n">PassContext</span><span class="p">(</span><span class="n">opt_level</span><span class="o">=</span><span class="mi">3</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Compile...&quot;</span><span class="p">)</span>
        <span class="n">lib</span> <span class="o">=</span> <span class="n">relay</span><span class="o">.</span><span class="n">build</span><span class="p">(</span><span class="n">mod</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="n">target</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">params</span><span class="p">)</span>
        <span class="n">evaluate_performance</span><span class="p">(</span><span class="n">lib</span><span class="p">,</span> <span class="n">data_shape</span><span class="p">)</span>

    <span class="c1"># compile kernels in kernel tuned only mode</span>
    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Evaluation of the network been tuned on kernel level:&quot;</span><span class="p">)</span>
    <span class="k">with</span> <span class="n">autotvm</span><span class="o">.</span><span class="n">apply_history_best</span><span class="p">(</span><span class="n">log_file</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Compile...&quot;</span><span class="p">)</span>
        <span class="k">with</span> <span class="n">tvm</span><span class="o">.</span><span class="n">transform</span><span class="o">.</span><span class="n">PassContext</span><span class="p">(</span><span class="n">opt_level</span><span class="o">=</span><span class="mi">3</span><span class="p">):</span>
            <span class="n">lib</span> <span class="o">=</span> <span class="n">relay</span><span class="o">.</span><span class="n">build</span><span class="p">(</span><span class="n">mod</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="n">target</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">params</span><span class="p">)</span>
        <span class="n">evaluate_performance</span><span class="p">(</span><span class="n">lib</span><span class="p">,</span> <span class="n">data_shape</span><span class="p">)</span>

    <span class="c1"># compile kernels with graph-level best records</span>
    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Evaluation of the network been tuned on graph level:&quot;</span><span class="p">)</span>
    <span class="k">with</span> <span class="n">autotvm</span><span class="o">.</span><span class="n">apply_graph_best</span><span class="p">(</span><span class="n">graph_opt_sch_file</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Compile...&quot;</span><span class="p">)</span>
        <span class="k">with</span> <span class="n">tvm</span><span class="o">.</span><span class="n">transform</span><span class="o">.</span><span class="n">PassContext</span><span class="p">(</span><span class="n">opt_level</span><span class="o">=</span><span class="mi">3</span><span class="p">):</span>
            <span class="n">lib</span> <span class="o">=</span> <span class="n">relay</span><span class="o">.</span><span class="n">build_module</span><span class="o">.</span><span class="n">build</span><span class="p">(</span><span class="n">mod</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="n">target</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">params</span><span class="p">)</span>
        <span class="n">evaluate_performance</span><span class="p">(</span><span class="n">lib</span><span class="p">,</span> <span class="n">data_shape</span><span class="p">)</span>


<span class="c1"># We do not run the tuning in our webpage server since it takes too long.</span>
<span class="c1"># Uncomment the following line to run it by yourself.</span>

<span class="c1"># tune_and_evaluate(tuning_option)</span>
</pre></div>
</div>
</div>
<div class="section" id="sample-output">
<h2>样本输出<a class="headerlink" href="#sample-output" title="永久链接至标题">¶</a></h2>
<p>The tuning needs to compile many programs and extract feature from them.
So a high performance CPU is recommended.
One sample output is listed below.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>Extract tasks...
Tuning...
<span class="o">[</span>Task  <span class="m">1</span>/12<span class="o">]</span>  Current/Best:  <span class="m">598</span>.05/2497.63 GFLOPS <span class="p">|</span> Progress: <span class="o">(</span><span class="m">252</span>/252<span class="o">)</span> <span class="p">|</span> <span class="m">1357</span>.95 s Done.
<span class="o">[</span>Task  <span class="m">2</span>/12<span class="o">]</span>  Current/Best:  <span class="m">522</span>.63/2279.24 GFLOPS <span class="p">|</span> Progress: <span class="o">(</span><span class="m">784</span>/784<span class="o">)</span> <span class="p">|</span> <span class="m">3989</span>.60 s Done.
<span class="o">[</span>Task  <span class="m">3</span>/12<span class="o">]</span>  Current/Best:  <span class="m">447</span>.33/1927.69 GFLOPS <span class="p">|</span> Progress: <span class="o">(</span><span class="m">784</span>/784<span class="o">)</span> <span class="p">|</span> <span class="m">3869</span>.14 s Done.
<span class="o">[</span>Task  <span class="m">4</span>/12<span class="o">]</span>  Current/Best:  <span class="m">481</span>.11/1912.34 GFLOPS <span class="p">|</span> Progress: <span class="o">(</span><span class="m">672</span>/672<span class="o">)</span> <span class="p">|</span> <span class="m">3274</span>.25 s Done.
<span class="o">[</span>Task  <span class="m">5</span>/12<span class="o">]</span>  Current/Best:  <span class="m">414</span>.09/1598.45 GFLOPS <span class="p">|</span> Progress: <span class="o">(</span><span class="m">672</span>/672<span class="o">)</span> <span class="p">|</span> <span class="m">2720</span>.78 s Done.
<span class="o">[</span>Task  <span class="m">6</span>/12<span class="o">]</span>  Current/Best:  <span class="m">508</span>.96/2273.20 GFLOPS <span class="p">|</span> Progress: <span class="o">(</span><span class="m">768</span>/768<span class="o">)</span> <span class="p">|</span> <span class="m">3718</span>.75 s Done.
<span class="o">[</span>Task  <span class="m">7</span>/12<span class="o">]</span>  Current/Best:  <span class="m">469</span>.14/1955.79 GFLOPS <span class="p">|</span> Progress: <span class="o">(</span><span class="m">576</span>/576<span class="o">)</span> <span class="p">|</span> <span class="m">2665</span>.67 s Done.
<span class="o">[</span>Task  <span class="m">8</span>/12<span class="o">]</span>  Current/Best:  <span class="m">230</span>.91/1658.97 GFLOPS <span class="p">|</span> Progress: <span class="o">(</span><span class="m">576</span>/576<span class="o">)</span> <span class="p">|</span> <span class="m">2435</span>.01 s Done.
<span class="o">[</span>Task  <span class="m">9</span>/12<span class="o">]</span>  Current/Best:  <span class="m">487</span>.75/2295.19 GFLOPS <span class="p">|</span> Progress: <span class="o">(</span><span class="m">648</span>/648<span class="o">)</span> <span class="p">|</span> <span class="m">3009</span>.95 s Done.
<span class="o">[</span>Task <span class="m">10</span>/12<span class="o">]</span>  Current/Best:  <span class="m">182</span>.33/1734.45 GFLOPS <span class="p">|</span> Progress: <span class="o">(</span><span class="m">360</span>/360<span class="o">)</span> <span class="p">|</span> <span class="m">1755</span>.06 s Done.
<span class="o">[</span>Task <span class="m">11</span>/12<span class="o">]</span>  Current/Best:  <span class="m">372</span>.18/1745.15 GFLOPS <span class="p">|</span> Progress: <span class="o">(</span><span class="m">360</span>/360<span class="o">)</span> <span class="p">|</span> <span class="m">1684</span>.50 s Done.
<span class="o">[</span>Task <span class="m">12</span>/12<span class="o">]</span>  Current/Best:  <span class="m">215</span>.34/2271.11 GFLOPS <span class="p">|</span> Progress: <span class="o">(</span><span class="m">400</span>/400<span class="o">)</span> <span class="p">|</span> <span class="m">2128</span>.74 s Done.
INFO Start to benchmark layout transformation...
INFO Benchmarking layout transformation successful.
INFO Start to run dynamic programming algorithm...
INFO Start forward pass...
INFO Finished forward pass.
INFO Start backward pass...
INFO Finished backward pass...
INFO Finished DPExecutor run.
INFO Writing optimal schedules to resnet-18_graph_opt.log successfully.

Evaluation of the network compiled in <span class="s1">&#39;default&#39;</span> mode without auto tune:
Compile...
Evaluate inference <span class="nb">time</span> cost...
Mean inference <span class="nb">time</span> <span class="o">(</span>std dev<span class="o">)</span>: <span class="m">4</span>.5 ms <span class="o">(</span><span class="m">0</span>.03 ms<span class="o">)</span>

Evaluation of the network been tuned on kernel level:
Compile...
Evaluate inference <span class="nb">time</span> cost...
Mean inference <span class="nb">time</span> <span class="o">(</span>std dev<span class="o">)</span>: <span class="m">3</span>.2 ms <span class="o">(</span><span class="m">0</span>.03 ms<span class="o">)</span>

Evaluation of the network been tuned on graph level:
Compile...
Config <span class="k">for</span> <span class="nv">target</span><span class="o">=</span>llvm -keys<span class="o">=</span>cpu -link-params<span class="o">=</span><span class="m">0</span>, <span class="nv">workload</span><span class="o">=(</span><span class="s1">&#39;dense_nopack.x86&#39;</span>, <span class="o">(</span><span class="s1">&#39;TENSOR&#39;</span>, <span class="o">(</span><span class="m">1</span>, <span class="m">512</span><span class="o">)</span>, <span class="s1">&#39;float32&#39;</span><span class="o">)</span>, <span class="o">(</span><span class="s1">&#39;TENSOR&#39;</span>, <span class="o">(</span><span class="m">1000</span>, <span class="m">512</span><span class="o">)</span>, <span class="s1">&#39;float32&#39;</span><span class="o">)</span>, None, <span class="s1">&#39;float32&#39;</span><span class="o">)</span> is missing in ApplyGraphBest context. A fallback configuration is used, which may bring great performance regression.
Config <span class="k">for</span> <span class="nv">target</span><span class="o">=</span>llvm -keys<span class="o">=</span>cpu -link-params<span class="o">=</span><span class="m">0</span>, <span class="nv">workload</span><span class="o">=(</span><span class="s1">&#39;dense_pack.x86&#39;</span>, <span class="o">(</span><span class="s1">&#39;TENSOR&#39;</span>, <span class="o">(</span><span class="m">1</span>, <span class="m">512</span><span class="o">)</span>, <span class="s1">&#39;float32&#39;</span><span class="o">)</span>, <span class="o">(</span><span class="s1">&#39;TENSOR&#39;</span>, <span class="o">(</span><span class="m">1000</span>, <span class="m">512</span><span class="o">)</span>, <span class="s1">&#39;float32&#39;</span><span class="o">)</span>, None, <span class="s1">&#39;float32&#39;</span><span class="o">)</span> is missing in ApplyGraphBest context. A fallback configuration is used, which may bring great performance regression.
Evaluate inference <span class="nb">time</span> cost...
Mean inference <span class="nb">time</span> <span class="o">(</span>std dev<span class="o">)</span>: <span class="m">3</span>.16 ms <span class="o">(</span><span class="m">0</span>.03 ms<span class="o">)</span>
</pre></div>
</div>
<div class="sphx-glr-footer class sphx-glr-footer-example docutils container" id="sphx-glr-download-how-to-tune-with-autotvm-tune-relay-x86-py">
<div class="sphx-glr-download docutils container">
<p><a class="reference download internal" download="" href="../../_downloads/6836ce26807b8d33b8f499287c1f3d04/tune_relay_x86.py"><code class="xref download docutils literal notranslate"><span class="pre">Python</span> <span class="pre">源码下载:</span> <span class="pre">tune_relay_x86.py</span></code></a></p>
</div>
<div class="sphx-glr-download docutils container">
<p><a class="reference download internal" download="" href="../../_downloads/910e6ecee4ecac8d8ca0baeb6d00689d/tune_relay_x86.ipynb"><code class="xref download docutils literal notranslate"><span class="pre">Jupyter</span> <span class="pre">notebook</span> <span class="pre">下载:</span> <span class="pre">tune_relay_x86.ipynb</span></code></a></p>
</div>
</div>
<p class="sphx-glr-signature"><a class="reference external" href="https://sphinx-gallery.github.io">Gallery generated by Sphinx-Gallery</a></p>
</div>
</div>


           </div>
           
          </div>
          

<footer>

    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="tune_relay_arm.html" class="btn btn-neutral float-right" title="Auto-tuning a Convolutional Network for ARM CPU" accesskey="n" rel="next">下一个 <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="tune_relay_cuda.html" class="btn btn-neutral float-left" title="Auto-tuning a Convolutional Network for NVIDIA GPU" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> 上一个</a>
      
    </div>

<div id="button" class="backtop"><img src="../../_static//img/right.svg" alt="backtop"/> </div>
<section class="footerSec">
    <div class="footerHeader">
      <ul class="d-flex align-md-items-center justify-content-between flex-column flex-md-row">
        <li class="copywrite d-flex align-items-center">
          <h5 id="copy-right-info">© 2020 Apache Software Foundation | All right reserved</h5>
        </li>
      </ul>

    </div>

    <ul>
      <li class="footernote">Copyright © 2020 The Apache Software Foundation. Apache TVM, Apache, the Apache feather, and the Apache TVM project logo are either trademarks or registered trademarks of the Apache Software Foundation.</li>
    </ul>

</section>
</footer>
        </div>
      </div>

    </section>

  </div>
  

    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

  </body>
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
    <!-- Theme Analytics -->
    <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-75982049-2', 'auto');
    ga('send', 'pageview');
    </script>

    
   

</body>
</html>